package factory

import (
	"github.com/gin-gonic/gin"
	"guns-go/model"
	"time"
)

func GenBaseSysOpLog(sysOpLog *model.SysOpLog, ip, location, browser, os, url, method string) {

	sysOpLog.Ip = ip
	sysOpLog.Location = location
	sysOpLog.Browser = browser
	sysOpLog.Os = os
	sysOpLog.Url = url
	sysOpLog.ReqMethod = method
}

func GenBaseSysVisLog(ip, location, browser, os string) *model.SysVisLog {

	sysVisLog := new(model.SysVisLog)

	sysVisLog.Ip = ip
	sysVisLog.Location = location
	sysVisLog.Browser = browser
	sysVisLog.Os = os

	return sysVisLog
}

//创建操作日志
func CreateSysOperationLog(sysOpLog *model.SysOpLog, c *gin.Context) {

	fillCommonSysOpLog(sysOpLog, c)

	sysOpLog.Success = "Y"
	sysOpLog.Message = "成功"
}

//创建异常日志
func CreateSysExceptionLog(sysOpLog *model.SysOpLog, c *gin.Context) {

	fillCommonSysOpLog(sysOpLog, c)

	sysOpLog.Success = "N"
	sysOpLog.Message = c.Errors.ByType(gin.ErrorTypePrivate).String()
}

func fillCommonSysOpLog(sysOpLog *model.SysOpLog, c *gin.Context) {

	className := ""

	methodName := ""

	sysOpLog.Name = ""
	var one int8
	one = 1
	sysOpLog.OpType = &one
	sysOpLog.ClassName = className
	sysOpLog.MethodName = methodName
	sysOpLog.OpTime = time.Now()
}

func CreateSysLoginLog(c *gin.Context) {

}

func CreateSysExitLog(c *gin.Context) {

}
